package com.icehand.axon.demo.command.aggregates;

import static org.axonframework.commandhandling.model.AggregateLifecycle.apply;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;

import org.axonframework.commandhandling.CommandHandler;
import org.axonframework.commandhandling.model.AggregateIdentifier;
import org.axonframework.eventhandling.EventHandler;
import org.axonframework.spring.stereotype.Aggregate;

import com.icehand.axon.demo.command.commands.TestCommand;
import com.icehand.axon.demo.common.events.TestCreatedEvent;

import lombok.NoArgsConstructor;
import lombok.extern.slf4j.Slf4j;

/**
 * @author icehand
 */
@Slf4j
@Entity
@NoArgsConstructor
@Aggregate
public class TestAccount {
	
	@AggregateIdentifier
	@Id
	private Integer id;
	
	@Column
	private String abc;
	
    @CommandHandler
    public TestAccount(TestCommand command) {
        log.debug("Construct a new TestAccount");
        apply(new TestCreatedEvent(command.getId(),command.getAbc()));
    }

    @EventHandler
    public void on(TestCreatedEvent event) {
        log.info("event");
        log.info("event:abc"+event.getAbc());
        
        this.id=event.getId();
        this.abc=event.getAbc();
    }
    
}
